package mytest;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class TreeTest {

	static class Tree{
		Tree lchild,rchild;
		char value;
	}
	
	static String preStr;
	static String inStr;
	static Tree rebuild(Tree root,boolean flag,int start,int end)
	{
		if(start>end)return root;
		int r=start;
		int t=preStr.indexOf(inStr.charAt(start));
		for(int i=start+1;i<=end;i++)
		{
			int s=preStr.indexOf(inStr.charAt(i));
			if(s<t){
				r=i;
				t=s;
			}
		}
		Tree p=new Tree();
		p.value=inStr.charAt(r);
		if(root==null)
		{
			root=p;
		}else{
			if(flag)
			{
				root.lchild=p;
			}else{
				root.rchild=p;
			}
		}
		rebuild(p, true, start, r-1);
		rebuild(p, false, r+1, end);
//		System.out.print(p.value);
		return root;
	}
	
	static void preOrder(Tree root)
	{
		Stack<Tree> stack=new Stack<Tree>();
		Tree p=root;
		while(!stack.isEmpty()||p!=null)
		{
			if(p!=null)
			{
				System.out.print(p.value);
				stack.push(p);
				p=p.lchild;
			}else{
				p=stack.pop().rchild;
			}
		}
	}
	
	static void inOrder(Tree root)
	{
		Stack<Tree> stack=new Stack<Tree>();
		Tree p=root;
		while(!stack.isEmpty()||p!=null)
		{
			if(p!=null)
			{
				stack.push(p);
				p=p.lchild;
			}else{
				p=stack.pop();
				System.out.print(p.value);
				p=p.rchild;
			}
		}
	}
	
	static void postOrder(Tree root)
	{
		Stack<Tree> stack=new Stack<Tree>();
		Stack<Integer> flag=new Stack<Integer>();
		Tree p=root;
		while(!stack.isEmpty()||p!=null)
		{
			if(p!=null)
			{
				stack.push(p);
				flag.push(0);
				p=p.lchild;
			}else{
				while(!flag.empty()&&flag.peek()==1)
				{
					flag.pop();
					System.out.print(stack.pop().value);
				}
				
				if(!flag.empty()){
					flag.pop();
					flag.push(1);
					p=stack.peek().rchild;
				}
			}
		}
	}
	
	static void postOrder2(Tree root)
	{
		Stack<Tree> stack=new Stack<Tree>();
		stack.push(root);
		while(!stack.isEmpty())
		{
			Tree p=stack.peek();
			if(p.lchild!=null)stack.push(p.lchild);
			else if(p.rchild!=null) stack.push(p.rchild);
			else{
				p=stack.pop();
				System.out.print(p.value);
				if(!stack.isEmpty())
				{
					if(stack.peek().lchild==p&&stack.peek().rchild!=null)
					{
							stack.push(stack.peek().rchild);
					}else{
						stack.pop();
					}
				}
			}
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer(bf.readLine());
		preStr=st.nextToken();
		inStr=st.nextToken();
		Tree root=null;
		root=rebuild(root, true, 0, inStr.length()-1);
		System.out.println();
//		preOrder(root);
//		System.out.println();
//		inOrder(root);
//		System.out.println();
		postOrder(root);
		System.out.println();
//		postOrder2(root);
//		System.out.println();
	}

}
